﻿namespace MicroCloud.Authorization
{
    /// <summary>
    /// 权限模块DTO实体映射
    /// </summary>
    public class AutoMapperAuthorizationConfiguration : AutoMapperTupleBase
    {
        #region "属性"
        #region "获取 服务提供者"
        /// <summary>
        /// 获取 服务提供者
        /// </summary>
        protected IServiceProvider ServiceProvider { get; }
        #endregion

        #endregion

        #region "构造函数"
        #region "初始化一个权限模块DTO实体映射的新实例"
        /// <summary>
        /// 初始化一个权限模块DTO实体映射 <see cref="AutoMapperAuthorizationConfiguration"/> 的新实例
        /// </summary>
        /// <param name="provider">服务提供者</param>
        public AutoMapperAuthorizationConfiguration(IServiceProvider provider)
        {
            ServiceProvider = provider;
        }
        #endregion

        #endregion

        #region "方法"
        #region "创建对象映射"
        /// <summary>
        /// 创建对象映射
        /// </summary>
        public override void CreateMap()
        {
            CreateMap<EntityRoleInputDto, EntityRole>()
                .ForMember(mr => mr.FilterGroupJson, opt => opt.MapFrom(dto => dto.FilterGroup.ToJsonString(false, false)));
            CreateMap<EntityUserInputDto, EntityUser>()
                .ForMember(mr => mr.FilterGroupJson, opt => opt.MapFrom(dto => dto.FilterGroup.ToJsonString(false, false)));
        }
        #endregion

        #endregion

    }

}
